package com.ruoyi.AliYunOss;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.UUID;

/**
 * @Description:
 * @Author: 吕宇宏
 * @Date: 2024/7/9 16:49
 */
@RestController
public class AliYunOssHandler {
    @Autowired
    private AliOssUtil aliOssUtil;


    public  String getUrl(String filePath,String end) throws IOException {

        FileInputStream fileInputStream = new FileInputStream(filePath);
        String s = UUID.randomUUID().toString()+end;
        String url = aliOssUtil.upload(fileInputStream, s);

            return url;



    }

    public  ResponseEntity getFileStream(String fileName, HttpServletResponse response) throws IOException {


        ResponseEntity<Object> download1 = aliOssUtil.download(fileName, response);


        return download1;



    }
}
